package com.wdf.project03.controller;

import com.wdf.project03.pojo.Dept;
import com.wdf.project03.pojo.Emp;
import com.wdf.project03.pojo.Result;
import com.wdf.project03.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    private DeptService deptService;
    @GetMapping()
    private Result selectAll(){
        List<Dept> depts = deptService.selectAll();
        return Result.success(depts);
    }
    @DeleteMapping("/{id}")
    private Result deleteById(@PathVariable Integer id){
        deptService.deleteById(id);
        return Result.success();
    }
    @PostMapping()
    private Result insertDept(@RequestBody Dept dept){
        deptService.insertDept(dept);
        return Result.success(dept);
    }
    @GetMapping("/{id}")
    private Result selectById(@PathVariable Integer id){
        Dept dept = deptService.selectById(id);
        return Result.success(dept);
    }
    @PutMapping()
    private Result updateById(@RequestBody Dept dept){
         deptService.updateDept(dept);
        return Result.success();
    }
}
